﻿using System;
using Microsoft.SharePoint;

namespace SharePoint.Orm.Wrappers {
	public class SPOrmSharePointRoleAssignment : ISPOrmRoleAssignment {
		private readonly SPRoleAssignment _roleAssignment;

		public SPOrmSharePointRoleAssignment(SPRoleAssignment roleAssignment) {
			_roleAssignment = roleAssignment;
		}

		public ISPOrmPrincipal Member {
			get {
				SPPrincipal principal = _roleAssignment.Member;
				if (principal is SPUser) {
					return new SPOrmSharePointUser((SPUser)principal);
				}
				if (principal is SPGroup) {
					return new SPOrmSharePointGroup((SPGroup)principal);
				}
				throw new SPOrmException("Could not convert type of member to SPOrm object (type: " + principal.GetType() + ")");
			}
		}
	}
}
